#pragma once

#include <QWidget>
#include <QDate>

class DetailData;
class STabCtrl;
class QHBoxLayout;
class SComboBox;
class SCheckEx;
class SImageButton;
class DualCalendars;
class QSpacerItem;
class SCheckComboBox;

class BondDetailDealChartTitle : public QWidget
{
	Q_OBJECT
public:
	BondDetailDealChartTitle(QWidget* parent);
	~BondDetailDealChartTitle();

    void setBondInfo(QSharedPointer<DetailData> data);
	void changeType(int start, int end);//将收到的Int转为QDate
	DualCalendars* getBrokerDualCalendars() { return m_BrokerDualCalendars; }
	DualCalendars* getCFETSDualCalendars() { return m_CFETSDualCalendars; }
	void onDualCalendarsGetDate(int start, int end);
	void onBondDateBtnChanged();
	void notify();
signals:
	void realTimeTabSelected();
	void dayAverTabSelected();
	void dayClosedTabSelected();
	void dateTabSelected(int);

protected:
	void paintEvent(QPaintEvent* event) override;
	void setupUi();
	void refreshUi();
	void clearCalendarlastSelected();

protected Q_SLOTS:
	void onBondTypeChanged();
	void onBrokerTabDealSelected(int index);
	void onBrokerTabDaySelected(int index);
	void onBrokerDateTabSelected(int index);
	void onCFETSTabDealSelected(int index);
	void onCFETSTabDaySelected(int index);
	void onCFETSDateTabSelected(int index);
	void onBrokerDateBtnSelected();
	void onCFETSDateBtnSelected();

private:
	int				m_bondType = 0;
	int				m_BrokerIndex = 0;
	int				m_CFETSindex = 0;
	bool			dateIsValid = false;
	bool			m_BrokerDay = false;
	bool			m_CFETSDay = false;

	QHBoxLayout*	m_layout = nullptr;
    QSharedPointer<DetailData>		m_data = nullptr;

	STabCtrl*		m_BrokerDealTab = nullptr;
	STabCtrl*		m_BrokerDayClosedTab = nullptr;

	STabCtrl*		m_CFETSdealTab = nullptr;
	STabCtrl*		m_CFETSdayClosedTab = nullptr;

	STabCtrl*		m_BrokerDealDateTab = nullptr;
	STabCtrl*		m_CFETSDealDateTab = nullptr;

	SImageButton*	m_BrokerDateBtn = nullptr;
	SImageButton*	m_CFETSDateBtn = nullptr;

	DualCalendars*  m_BrokerDualCalendars = nullptr;
	DualCalendars*  m_CFETSDualCalendars = nullptr;

	QDate startD;
	QDate endD;
};

class BondDetailQuoteChartTitle : public QWidget
{
	Q_OBJECT
public:
	BondDetailQuoteChartTitle(QWidget* parent);
	~BondDetailQuoteChartTitle();
	void notify();
    void setBondInfo(QSharedPointer<DetailData> data);

protected:
	void paintEvent(QPaintEvent* event) override;
	void setupUi();
	void refreshUi();


signals:
	void yieldSelected();
	void netPriceSelected();
	void filterAbValueSelected(int);

protected Q_SLOTS:
	void onBondTypeChanged();
	void onBrokerStateChanged();
	void onCFETSStateChanged();
	void onBrokerItemSelected(int index);
	void onCFETSItemSelected(int index);

private:
	int				m_bondType = 0;
	int				m_BrokerIndex = 0;
	int				m_CFETSindex = 0;

	QHBoxLayout*	m_rateLayout = nullptr;
    QSharedPointer<DetailData>		m_data = nullptr;
	
	SComboBox*		m_BrokerCombox = nullptr;
	SComboBox*		m_CFETSCombox = nullptr;

	SCheckEx*		m_BrokerFilAbnValCheck =  nullptr;
	SCheckEx*		m_CFETSFilAbnValCheck = nullptr;

	bool			m_BrokerFilterAbnormalVal = true;
	bool			m_CFETSFilterAbnormalVal = true;
};

class BondDetailRateChartTitle : public QWidget
{
	Q_OBJECT
public:
	BondDetailRateChartTitle(QWidget* parent);
	~BondDetailRateChartTitle();

    void setBondInfo(QSharedPointer<DetailData> data);
	void refreshUi();
	void notify();

signals:
	void creditSpreadSelected(int);
	void yieldSelected(int);

protected:
	void paintEvent(QPaintEvent* event) override;
	void setupUi();
	void setCreditSpreadTabText();
	
	QString getCreditSpreadTabFirstText();
	QString getYieldCurveTitle();

protected Q_SLOTS:
	void onBrokerCreditSpreadTabSelected(int index);
	void onBrokerBondAdIssureTabSelected(int index);
	void onBrokerYieldTabSelected(int index);
	void onCFETSCreditSpreadTabSelected(int index);
	void onCFETSBondAdIssureTabSelected(int index);
	void onCFETSYieldTabSelected(int index);
	void onBondTypeChanged();

private:
	int				m_bondType = 0;
	int				m_nWndType = 0;
    QSharedPointer<DetailData>		m_data = nullptr;
	
	STabCtrl*		m_BrokerCreditSpreadTab = nullptr;
	STabCtrl*		m_BrokerBondAdIssureTab = nullptr;
	STabCtrl*		m_BrokerYieldTab = nullptr;

	STabCtrl*		m_CFETSCreditSpreadTab = nullptr;
	STabCtrl*		m_CFETSBondAdIssureTab = nullptr;
	STabCtrl*		m_CFETSYieldTab = nullptr;
	QSpacerItem*	m_spaceItem = nullptr;
};

class BondDetailCDCChartTitle : public QWidget
{
	Q_OBJECT
public:
	BondDetailCDCChartTitle(QWidget* parent);
	~BondDetailCDCChartTitle();
    void setBondInfo(QSharedPointer<DetailData> data);
	void changeType(int start,int end);//将收到的Int转为QDate
	DualCalendars* getBrokerDualCalendars() { return m_BrokerDualCalendars; }
	DualCalendars* getCFETSDualCalendars() { return m_CFETSDualCalendars; }
	void onDualCalendarsGetDate(int start, int end);
	void onBondDateBtnChanged();
	void notify();
//signals:
//	void yieldTabSelected(int,int,int);
//	void netPriceTabSelected(int,int,int);
//	void dateTabSelected(int);
signals:
	void yieldTabSelected(int,int); // 参数:估值/成交
	void netPriceTabSelected(int, int); //参数:估值/成交
	void dateTabSelected(int); //日期tab

protected Q_SLOTS:
	void onBondTypeChanged();
	void onBrokerTabSelected(int index);
	void onCFETSTabSelected(int index);
	void onBrokerChecked();
	void onCFETSChecked();
	void onBrokerDateSelected(int index);
	void onCFETSDateSelected(int index);
	void onBrokerDateBtnSelected();
	void onCFETSDateBtnSelected();

protected:
	void paintEvent(QPaintEvent* event) override;
	void setupUi();
	void refreshUi();
	bool optionBond(); //判断行权,行权是在选择净价时,broker和cfets行情都没有估值
	void clearCalendarlastSelected();

private:
	int				m_bondType = 0;
	bool			dateIsValid = false;
    QSharedPointer<DetailData>		m_data = nullptr;

	STabCtrl*		m_BrokerCDCTab = nullptr;
	STabCtrl*		m_CFETSCDCTab = nullptr;
	
	SCheckComboBox* m_BrokerCBox = nullptr;
	SCheckComboBox* m_CFETSCBox = nullptr;
		
	STabCtrl*		m_BrokerDateTab = nullptr;
	STabCtrl*		m_CFETSDateTab = nullptr;

	std::vector<int>		m_checkValue; // 记录Broker/CFETS checkbox的值

	QHBoxLayout*	m_cdcHLayout = nullptr;	

	QSpacerItem*	m_BrokerSpaceItemEst = nullptr;
	QSpacerItem*	m_CFETSSpaceItemEst = nullptr;

	SImageButton*	m_BrokerDateBtn = nullptr;
	SImageButton*	m_CFETSDateBtn = nullptr;

	DualCalendars*  m_BrokerDualCalendars = nullptr;
	DualCalendars*  m_CFETSDualCalendars = nullptr;

	QDate startD;
	QDate endD;
};
